// import-history.js - 导入历史页面的逻辑
const storageManager = require('../../../manager/storageManager.js');

Page({
  data: {
    importHistory: [],
    isLoading: false
  },

  // 页面加载
  onLoad: function() {
    this.loadImportHistory();
  },

  // 加载导入历史
  loadImportHistory: function() {
    this.setData({ isLoading: true });
    try {
      const history = storageManager.getStorage(storageManager.STORAGE_KEYS.IMPORT_HISTORY) || [];
      this.setData({
        importHistory: history,
        isLoading: false
      });
    } catch (error) {
      console.error('加载导入历史失败:', error);
      wx.showToast({ title: '加载失败', icon: 'none' });
      this.setData({ isLoading: false });
    }
  },

  // 下拉刷新
  onPullDownRefresh: function() {
    this.loadImportHistory();
    wx.stopPullDownRefresh();
  },

  // 格式化日期时间
  formatDateTime: function(date) {
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0');
    const day = String(date.getDate()).padStart(2, '0');
    const hours = String(date.getHours()).padStart(2, '0');
    const minutes = String(date.getMinutes()).padStart(2, '0');
    return `${year}-${month}-${day} ${hours}:${minutes}`;
  }
});